package com.rambo.dsd.sys.ws.impl;

import com.rambo.dsd.sys.dao.inter.UserDao;
import com.rambo.dsd.sys.dao.inter.po.UserPO;
import com.rambo.dsd.sys.ws.inter.UserWs;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import java.util.List;


@Component
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class UserWsImpl implements UserWs {
    @Autowired
    private UserDao userPODao;

    @Override
    public UserPO getUser(String id) {
        UserPO userPO = userPODao.getByKey(id);
        return userPO != null ? userPO : new UserPO();
    }

    @Override
    public List<UserPO> listUser(UserPO userPO) {
        return userPODao.findByExample(userPO);
    }

    @Override
    public List<UserPO> listUserOrdrBy(UserPO userPO, String orderby, Boolean asc) {
        return userPODao.findByExample(userPO, asc ? Order.asc(orderby) : Order.desc(orderby));
    }

    @Override
    public UserPO addUser(UserPO userPO) {
        return userPODao.add(userPO);
    }

    @Override
    public UserPO updateUser(UserPO userPO) {
        return userPODao.edit(userPO);
    }

}